<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use common\models\Category;
use yii\helpers\ArrayHelper;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\WebsiteSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Websites');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="website-index">

    <p>
        <?= Html::a(Yii::t('app', 'Create Website'), ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?php Pjax::begin(); ?>    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            [
                'attribute' => 'category_id',
                'value' => function ($model) {
                    return $model->category->name;
                },
                'filter' => Category::Select($searchModel->category_id,'WebsiteSearch[category_id]','class="form-control"'),
            ],
            [
                'attribute' => 'title',
                'value' => function ($model) {
                    return Html::a(mb_substr($model->title,0,20,'utf-8'), $model->url, ['target' => $model->id, 'data-pjax' => 0]);
                },
                'format' => 'raw',
            ],
            [
                'attribute' => 'desc',
                'value' => function ($model) {
                    return mb_substr($model->desc, 0, 20,'utf-8');
                }
            ],
            'page_view',

            'create_at:datetime',
            'update_at:datetime',
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
    <?php Pjax::end(); ?></div>
